#############################################################################
## Start of the Makefile ## Suggestions are welcome ## All rights reserved ##
ifdef WX_HOME
  WXBASEDIR=$(WX_HOME)
else
  WXBASEDIR=E:\wxWidgets
endif

WX_RELEASE_NODOT = 29

# The executable file name.
# If not specified, current directory name or `test.out' will be used.
PROGRAM=gelifive

# The directories in which source files reside.
# If not specified, only the current directory will be serached.
HEADER_DIRS=header
SRC_DIRS=src
OBJS_DIR=obj

RC_HOME=
#for rc file of application, note: no extension name
PROGRAM_RC:=sample

##==========================================================================
## Implicit Section: change the following only when necessary.
##==========================================================================

# The source file types (headers excluded).
# .cpp indicates C++ source files.
SRC_EXTS=.cpp .CPP

# The header file types.
HDR_EXTS=.h .H

# Standard linker flags 
LDFLAGS?= 


# The C++ program compiler.
CXX=g++

# Un-comment the following line to compile C programs as C++ ones.
CC=$(CXX)

# The command used to delete file.
RM=rm -rf

##==========================================================================
## Stable Section: usually no need to be changed. But you can add more.
##==========================================================================
SPACE=$(EMPTY) $(EMPTY)

ifeq ($(PROGRAM),)
  CUR_PATH_NAMES=$(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))
  PROGRAM=$(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))
	ifeq ($(PROGRAM),)
	  PROGRAM=test.out
	endif
endif

ifeq ($(HEADER_DIRS),)
  HEADER_DIRS=.
endif

ifeq ($(SRC_DIRS),)
  SRC_DIRS=.
endif

ifeq ($(OBJS_DIR),)
  OBJS_DIR=.
endif

SOURCES = $(foreach d,$(SRC_DIRS),$(wildcard $(addprefix $(d)/*,$(SRC_EXTS))))
HEADERS = $(foreach d,$(HEADER_DIRS),$(wildcard $(addprefix $(d)/*,$(HDR_EXTS))))
OBJS    = $(addprefix $(OBJS_DIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES)))))


## Define some useful variables.
COMPILE.cxx = $(CXX) $(CXXFLAGS) -c
LINK.cxx    = $(CXX) $(CXXFLAGS)

# What type of library to build? [0,1]
SHARED ?= 0

# Build wxUniversal instead of native port? [0,1]
WXUNIV ?= 0

# Compile Unicode build of wxWidgets? [0,1]
UNICODE ?= 1

# Use MSLU library when building Unicode version. [0,1]
MSLU ?= 0

# Type of compiled binaries [debug,release]
BUILD ?= release

# Should debugging info be included in the executables? The default value
# "default" means that debug info will be included if BUILD=debug
# and not included if BUILD=release. [0,1,default]
DEBUG_INFO ?= default

# Should __WXDEBUG__ be defined? The default value "default" means that it will
# be defined if BUILD=debug and not defined if BUILD=release. [0,1,default]
DEBUG_FLAG ?= default

# Multiple libraries or single huge monolithic one? [0,1]
MONOLITHIC ?= 1

# Build GUI libraries? [0,1]
USE_GUI ?= 1

# Build wxHTML library (USE_GUI must be 1)? [0,1]
USE_HTML ?= 1

# Build multimedia library (USE_GUI must be 1)? [0,1]
USE_MEDIA ?= 1

# Build wxXRC library (USE_GUI must be 1)? [0,1]
USE_XRC ?= 1

# Build wxAUI library (USE_GUI must be 1)? [0,1]
USE_AUI ?= 1

# Build wxRichTextCtrl library (USE_GUI must be 1)? [0,1]
USE_RICHTEXT ?= 1

# Build OpenGL canvas library (USE_GUI must be 1)? [0,1]
USE_OPENGL ?= 1

# Build ODBC database classes (USE_GUI must be 1)? [0,1]
USE_ODBC ?= 0

# Build quality assurance classes library (USE_GUI must be 1)? [0,1]
USE_QA ?= 0

# Enable exceptions in compiled code. [0,1]
USE_EXCEPTIONS ?= 1

# Enable run-time type information (RTTI) in compiled code. [0,1]
USE_RTTI ?= 1

# Enable threading in compiled code. [0,1]
USE_THREADS ?= 1

# Enable wxCairoContext for platforms other than Linux/GTK. [0,1]
USE_CAIRO ?= 0

# Link with gdiplus.lib? (Needed for wxGraphicsContext, will also set wxUSE_GRAPHICS_CONTEXT) [0,1]
USE_GDIPLUS ?= 0

# Is this official build by wxWidgets developers? [0,1]
OFFICIAL_BUILD ?= 0

# Use this to name your customized DLLs differently 
VENDOR ?= custom

#  
WX_FLAVOUR ?= 

#  
WX_LIB_FLAVOUR ?= 

# Name of your custom configuration. This affects directory
# where object files are stored as well as the location of
# compiled .lib files and setup.h under the lib/ toplevel directory. 
CFG ?= 

# Compiler flags needed to compile test suite in tests directory. If you want
# to run the tests, set it so that the compiler can find CppUnit headers. 
CPPUNIT_CFLAGS ?= 

# Linker flags needed to link test suite in tests directory. If you want
# to run the tests, include CppUnit library here. 
CPPUNIT_LIBS ?= 

# Version of C runtime library to use. You can change this to
# static if SHARED=0, but it is highly recommended to not do
# it if SHARED=1 unless you know what you are doing. [dynamic,static]
RUNTIME_LIBS ?= static

# Set the version of your Mingw installation here.
#     "3" ...... this is for Mingw 2.0 or newer (comes with gcc3)
#     "2.95" ... for Mingw 1.1 or any of the older versions [3,2.95]
GCC_VERSION ?= 3


##==========================================================================
# Do not modify the rest of this file!
##==========================================================================


### Variables: ###

	
LIBDIRNAME = $(WXBASEDIR)\lib\gcc_$(LIBTYPE_SUFFIX)$(CFG)

SETUPHDIR = $(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)

PROGRAM_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(GCCFLAGS) $(__THREADSFLAG) \
	$(STATIC_GCCFLAGS) -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
	$(__DEBUG_DEFINE_p) $(__NDEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) \
	$(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p) \
	$(__MSLU_DEFINE_p) $(__GFXCTX_DEFINE_p) -I$(SETUPHDIR) \
	-I$(WXBASEDIR)\include \
	$(____CAIRO_INCLUDEDIR_FILENAMES_p) -Wall -W $(__DLLFLAG_p) \
	-I$(HEADER_DIRS) \
	-I$(SRC_DIRS) \
	-DNOPCH $(__RTTIFLAG_5) $(__EXCEPTIONSFLAG_6) \
	-Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)

PROGRAM_OBJECTS = $(addprefix $(OBJS_DIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES)))))
ifneq ($(RC_RIR),)
PROGRAM_OBJECTS += $(OBJS_DIR)/$(PROGRAM)_resource_rc.o
PROGRAM_RC = $(OBJS_DIR)/$(PROGRAM_RC).rc
endif

### Conditionally set variables: ###

ifeq ($(GCC_VERSION),2.95)
GCCFLAGS = -fvtable-thunks
endif

ifeq ($(USE_GUI),0)
PORTNAME = base
endif

ifeq ($(USE_GUI),1)
PORTNAME = msw
__LIB_JPEG_p = -lwxjpeg$(WXDEBUGFLAG)
__LIB_PNG_p = -lwxpng$(WXDEBUGFLAG)
endif


ifeq ($(UNICODE),1)
WXUNICODEFLAG = u
__UNICODE_DEFINE_p = -D_UNICODE
__UNICODE_DEFINE_p_1 = --define _UNICODE
endif

ifeq ($(SHARED),0)
LIBTYPE_SUFFIX = lib
STATIC_GCCFLAGS = -static -static-libgcc -enable-stdcall-fixup
endif

ifeq ($(SHARED),1)
WXDLLFLAG = dll
LIBTYPE_SUFFIX = dll
__DLLFLAG_p = -DWXUSINGDLL
__DLLFLAG_p_1 = --define WXUSINGDLL
endif

ifeq ($(MONOLITHIC),0)
EXTRALIBS_FOR_BASE =
__WXLIB_NET_p = -lwxbase$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_net
__WXLIB_CORE_p = -lwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core
__WXLIB_BASE_p = -lwxbase$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)
endif

ifeq ($(MONOLITHIC),1)
EXTRALIBS_FOR_BASE =
__WXLIB_MONO_p = -lwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)
__LIB_TIFF_p = -lwxtiff$(WXDEBUGFLAG)
endif


ifeq ($(USE_RTTI),0)
__RTTIFLAG_5 = -fno-rtti
__RTTI_DEFINE_p = -DwxNO_RTTI
__RTTI_DEFINE_p_1 = --define wxNO_RTTI
endif

ifeq ($(USE_RTTI),1)
__RTTIFLAG_5 = 
endif

ifeq ($(USE_EXCEPTIONS),0)
__EXCEPTIONSFLAG_6 = -fno-exceptions
__EXCEPTIONS_DEFINE_p = -DwxNO_EXCEPTIONS
__EXCEPTIONS_DEFINE_p_1 = --define wxNO_EXCEPTIONS
endif

ifeq ($(USE_EXCEPTIONS),1)
__EXCEPTIONSFLAG_6 = 
endif

ifeq ($(WXUNIV),1)
WXUNIVNAME = univ
__WXUNIV_DEFINE_p = -D__WXUNIVERSAL__
__WXUNIV_DEFINE_p_1 = --define __WXUNIVERSAL__
endif

ifeq ($(BUILD),debug)
__OPTIMIZEFLAG_2 = -O0
ifeq ($(DEBUG_FLAG),default)
WXDEBUGFLAG = d
__DEBUG_DEFINE_p = -D__WXDEBUG__
__DEBUG_DEFINE_p_1 = --define __WXDEBUG__
__DEBUGINFO = -g
endif
endif

ifeq ($(DEBUG_FLAG),1)
WXDEBUGFLAG = d
__DEBUG_DEFINE_p = -D__WXDEBUG__
__DEBUG_DEFINE_p_1 = --define __WXDEBUG__
endif

ifeq ($(BUILD),release)
__OPTIMIZEFLAG_2 = -O2
__NDEBUG_DEFINE_p = -DNDEBUG
__NDEBUG_DEFINE_p_1 = --define NDEBUG
ifeq ($(DEBUG_INFO),default)
__DEBUGINFO =
endif
endif

ifeq ($(USE_THREADS),0)
__THREAD_DEFINE_p = -DwxNO_THREADS
__THREAD_DEFINE_p_1 = --define wxNO_THREADS
__THREADSFLAG =
endif

ifeq ($(USE_THREADS),1)
__THREADSFLAG = -mthreads
endif

ifeq ($(MSLU),1)
__MSLU_DEFINE_p = -DwxUSE_UNICODE_MSLU=1
__MSLU_DEFINE_p_1 = --define wxUSE_UNICODE_MSLU=1
__UNICOWS_LIB_p = -lunicows
endif

ifeq ($(USE_GDIPLUS),1)
__GFXCTX_DEFINE_p = -DwxUSE_GRAPHICS_CONTEXT=1
__GFXCTX_DEFINE_p_1 = --define wxUSE_GRAPHICS_CONTEXT=1
__GDIPLUS_LIB_p = -lgdiplus
endif

ifeq ($(USE_CAIRO),1)
____CAIRO_INCLUDEDIR_FILENAMES_p = -I$(CAIRO_ROOT)\include\cairo
__CAIRO_INCLUDEDIR_p = --include-dir $(CAIRO_ROOT)/include/cairo
__CAIRO_LIB_p = -lcairo
____CAIRO_LIBDIR_FILENAMES_p = -L$(CAIRO_ROOT)\lib
endif

ifeq ($(DEBUG_INFO),0)
__DEBUGINFO =
endif

ifeq ($(DEBUG_INFO),1)
__DEBUGINFO = -g
endif

ifeq ($(USE_OPENGL),1)
__OPENGL_LIB_p = -lwxmsw$(WX_RELEASE_NODOT)u_gl$(SPACE)-lopengl32$(SPACE)-lglu32
endif

ifeq ($(USE_ODBC),1)
__ODBC_LIB_p = -lodbc32
endif

CPPDEPS = -MT $@ -MF $@.d -MD -MP

##==========================================================================
### Targets: ###
##==========================================================================
.PHONY: all objs clean show


all: MD $(OBJS_DIR)/$(PROGRAM).exe

MD:
	test -d $(OBJS_DIR) || mkdir $(OBJS_DIR)

$(OBJS_DIR)/$(PROGRAM).exe: $(PROGRAM_OBJECTS) 
	$(CXX) -o $@ $(PROGRAM_OBJECTS) $(__DEBUGINFO) \
	$(__THREADSFLAG) -L"$(LIBDIRNAME)" -Wl,--subsystem,windows \
	-mwindows $(____CAIRO_LIBDIR_FILENAMES_p) $(LDFLAGS) \
	$(__WXLIB_CORE_p) $(__WXLIB_NET_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) \
	$(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) \
	-lwxzlib$(WXDEBUGFLAG) \
	-lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) \
	-lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) \
	$(__UNICOWS_LIB_p) \
	$(__GDIPLUS_LIB_p) \
	$(__CAIRO_LIB_p) \
	-lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm \
	-lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 \
	-ladvapi32 -lwsock32 -lwininet $(__OPENGL_LIB_p) \
	$(__ODBC_LIB_p)

$(OBJS_DIR)/%.o:$(SRC_DIRS)/%.cpp
	$(COMPILE.cxx) $(PROGRAM_CXXFLAGS) $(CPPDEPS) $< -o $@

clean:
	$(RM) $(OBJS) $(PROGRAM) $(OBJS_DIR)/$(PROGRAM).exe $(OBJS_DIR)

# Show variables (for debug use only.)
show:
	@echo 'PROGRAM     :' $(PROGRAM)
	@echo 'SRC_DIRS    :' $(SRC_DIRS)
	@echo 'HEADERS     :' $(HEADERS)
	@echo 'SOURCES     :' $(SOURCES)
	@echo 'OBJS        :' $(OBJS)
	@echo 'COMPILE.cxx :' $(COMPILE.cxx)
	@echo 'link.cxx    :' $(LINK.cxx)

## End of the Makefile ##  Suggestions are welcome  ## All rights reserved ##
#############################################################################